
timeDir=0.1

bc_name="TOP_2D GROUND_2D WEST_2D EAST_2D SOUTH_2D NORTH_2D WALLS_2D"

# |           |       p      |   U                          |
# | ----      |       ----   |  --------                    | 
# | TOP_2D    | symmetry     | symmetry                     |
# | GROUND_2D | zeroGradient | noSlip                       |
# | WEST_2D   | symmetry     | symmetry                     |
# | EAST_2D   | symmetry     | symmetry                     |
# | SOUTH_2D  | totalPressure| pressureInletOutletVelocity  |
# | NORTH_2D  | zeroGradient | fixedValue                   |
# | WALLS_2D  | zeroGradient | noSlip                       |

# NOTE: 入口: NORTH_2D, 出口: SOUTH_2D


# example of totalPressure 
# outlet
# {
#     type            totalPressure;
#     rho             rho;
#     psi             none;
#     gamma           1;
#     p0              uniform 0;
#     value           nonuniform List<scalar> 

show_bc=false

if $show_bc; then
    all_field="p U"
    for field in $all_field
    do
        echo "Start of $field"
        for bc in $bc_name
        do
            echo "in $field, the $bc type is: " 
            echo "-----------$bc---------------"
            grep -C 4 "$bc" $timeDir/$field
            echo "-----------$bc---------------"

        done

        echo "End of $field"
    done
fi


# 转换具有计算结果的边界条件
# 计算的某些边界带有value nonuniform分布，
# 采用foamDictionary .. -remove或者 -set重新设置边界条件

init_convert_bc=false

if $init_convert_bc; then
echo "*************Converting BC*********************************************"

foamDictionary 0.1/p -entry boundaryField.TOP_2D.type -set "symmetry"
# foamDictionary 0.1/p -entry boundaryField.TOP_2D.value -set "value uniform 0"
foamDictionary 0.1/p -entry boundaryField.TOP_2D.value -remove

foamDictionary 0.1/p -entry boundaryField.GROUND_2D.type -set "zeroGradient"
# foamDictionary 0.1/p -entry boundaryField.GROUND_2D.value -set "value uniform 0"
foamDictionary 0.1/p -entry boundaryField.GROUND_2D.value -remove

foamDictionary 0.1/p -entry boundaryField.WEST_2D.type -set "symmetry"
# foamDictionary 0.1/p -entry boundaryField.WEST_2D.value -set "value uniform 0"
foamDictionary 0.1/p -entry boundaryField.WEST_2D.value -remove

foamDictionary 0.1/p -entry boundaryField.EAST_2D.type -set "symmetry"
# foamDictionary 0.1/p -entry boundaryField.EAST_2D.value -set "value uniform 0"
foamDictionary 0.1/p -entry boundaryField.EAST_2D.value -remove

foamDictionary 0.1/p -entry boundaryField.SOUTH_2D.type -set "totalPressure"
# foamDictionary 0.1/p -entry boundaryField.SOUTH_2D.value -set "value uniform 0"
foamDictionary 0.1/p -entry boundaryField.SOUTH_2D.value -remove
foamDictionary 0.1/p -entry boundaryField.SOUTH_2D.p0 -set "uniform 0"

foamDictionary 0.1/p -entry boundaryField.NORTH_2D.type -set "zeroGradient"
# foamDictionary 0.1/p -entry boundaryField.NORTH_2D.value -set "value uniform 0"
foamDictionary 0.1/p -entry boundaryField.NORTH_2D.value -remove

foamDictionary 0.1/p -entry boundaryField.WALLS_2D.type -set "zeroGradient"
# foamDictionary 0.1/p -entry boundaryField.WALLS_2D.value -set "value uniform 0"
foamDictionary 0.1/p -entry boundaryField.WALLS_2D.value -remove


# U

foamDictionary 0.1/U -entry boundaryField.TOP_2D.type -set "symmetry"
# foamDictionary 0.1/U -entry boundaryField.TOP_2D.value -set "value uniform (0 0 0)"
foamDictionary 0.1/U -entry boundaryField.TOP_2D.value -remove

foamDictionary 0.1/U -entry boundaryField.GROUND_2D.type -set "noSlip"
# foamDictionary 0.1/U -entry boundaryField.GROUND_2D.value -set "value uniform (0 0 0)"
foamDictionary 0.1/U -entry boundaryField.GROUND_2D.value -remove


foamDictionary 0.1/U -entry boundaryField.WEST_2D.type -set "symmetry"
# foamDictionary 0.1/U -entry boundaryField.WEST_2D.value -set "value uniform (0 0 0)"
foamDictionary 0.1/U -entry boundaryField.WEST_2D.value -remove

foamDictionary 0.1/U -entry boundaryField.EAST_2D.type -set "symmetry"
# foamDictionary 0.1/U -entry boundaryField.EAST_2D.value -set "value uniform (0 0 0)"
foamDictionary 0.1/U -entry boundaryField.EAST_2D.value -remove

foamDictionary 0.1/U -entry boundaryField.SOUTH_2D.type -set "pressureInletOutletVelocity"
foamDictionary 0.1/U -entry boundaryField.SOUTH_2D.value -set "uniform (0 0 0)"
# foamDictionary 0.1/U -entry boundaryField.SOUTH_2D.value -remove

foamDictionary 0.1/U -entry boundaryField.NORTH_2D.type -set "fixedValue"
foamDictionary 0.1/U -entry boundaryField.NORTH_2D.value -set "uniform (1 0 0)"
# foamDictionary 0.1/U -entry boundaryField.NORTH_2D.value -remove

foamDictionary 0.1/U -entry boundaryField.WALLS_2D.type -set "noSlip"
# foamDictionary 0.1/U -entry boundaryField.WALLS_2D.value -set "value uniform (0 0 0)"
foamDictionary 0.1/U -entry boundaryField.WALLS_2D.value -remove
echo "*************Done convert BC*********************************************"

fi

# 测试出入口边界条件设置对计算的影响
test_convert_bc=true
if $test_convert_bc; then

# method 1，已在convert bc时设置, windAroundBuildings in ofv2306
#   | inlet | outlet |
# p | zeroGradient | totalPressure
# U | fixedVaule | pressureInletOutletVelocity

# method 2, simpleCar in ofv2306
#   | inlet | outlet |
# p | zeroGradient | fixedValue | 
# U | fixedValue | pressureInletOutletVelocity

# foamDictionary 0.1/U -entry boundaryField.SOUTH_2D.type -set "pressureInletOutletVelocity"
# foamDictionary 0.1/U -entry boundaryField.SOUTH_2D.value -set "uniform (1 0 0)"
# foamDictionary 0.1/U -entry boundaryField.NORTH_2D.type -set "fixedValue"
# foamDictionary 0.1/U -entry boundaryField.NORTH_2D.value -set "uniform (1 0 0)"
# foamDictionary 0.1/p -entry boundaryField.SOUTH_2D.type -set "fixedValue"
# foamDictionary 0.1/p -entry boundaryField.SOUTH_2D.p0 -remove
# foamDictionary 0.1/p -entry boundaryField.SOUTH_2D.value -set "uniform 0"
# foamDictionary 0.1/p -entry boundaryField.NORTH_2D.type -set "zeroGradient"

# simpleFoam | tee log.method_2

# method 3, turbulentFlatPlate in ofv2306
#   | inlet | outlet |
# p | zeroGradient | fixedValue
# U | fixedValue | zeroGradient | NOTE: zeroGradient in velocity

foamDictionary 0.1/U -entry boundaryField.SOUTH_2D.type -set "zeroGradient"
foamDictionary 0.1/U -entry boundaryField.SOUTH_2D.value -remove
foamDictionary 0.1/U -entry boundaryField.NORTH_2D.type -set "fixedValue"
foamDictionary 0.1/U -entry boundaryField.NORTH_2D.value -set "uniform (1 0 0)"

foamDictionary 0.1/p -entry boundaryField.SOUTH_2D.type -set "fixedValue"
foamDictionary 0.1/p -entry boundaryField.SOUTH_2D.p0 -remove
foamDictionary 0.1/p -entry boundaryField.SOUTH_2D.value -set "uniform 0"
foamDictionary 0.1/p -entry boundaryField.NORTH_2D.type -set "zeroGradient"

simpleFoam | tee log.method_3



# method 4, airfoil in ofv2306
#   | inlet | outlet |
# p | freestreamPressure | freestreamPressure
# U | freestreamVelocity | freestreamVelocity

# method 5, motorBike in ofv2306
#   | inlet | outlet |
# p | zeroGradient | fixedValue
# U | fixedValue | inletOutlet

fi


echo "Done processing"